﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace EmotionPlotter
{
    /// <summary>
    /// Interaction logic for Window2.xaml
    /// </summary>
    public partial class Window2 : Window
    {
        public Window2()
        {
            InitializeComponent();
        }
        PlotEmotion pe;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            pe = new PlotEmotion();
            pe.Show();
            EmotionLevels.EmotionLevelChanged += new EventHandler(EmotionLevels_EmotionLevelChanged);
            //emotionLevels1.NegativeEmotionName = "Hate";
            //emotionLevels1.PositiveEmotionName = "Love";
        }

        void EmotionLevels_EmotionLevelChanged(object sender, EventArgs e)
        {
            ObservableCollection<EmotionLevels> emotions =
             this.emotionLevelCollection1.GetEmotions;

            Double val = 0;
            Double valTheta = 0;
            Double valCompleteX = 0;
            Double valCompleteY = 0;
            foreach (EmotionLevels el in emotions)
            {
                if (!el.IsExcluded)
                {
                    val = el.PositiveEmotionValue;
                    valTheta = el.Angle;// *val / 250;
                    valCompleteX += val * Math.Sin(valTheta * Math.PI / 180 + Math.PI / 2);
                    valCompleteY += val * Math.Cos(valTheta * Math.PI / 180 + Math.PI / 2);
                }
            }

            
            if (val > 250)
                val = 250;

            if (Double.IsInfinity(valTheta))
            {
                val = 0;
                valTheta = 0;
            }
             
            pe.LocationMomentPtr = new System.Windows.Point(valCompleteX, valCompleteY);
        }
        AddEmotion addEmotion = new AddEmotion();
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            button1.IsEnabled = false;
            addEmotion.CollectionPtr = this.emotionLevelCollection1;
            addEmotion.ShowDialog();
        }

//#error not correct output
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<EmotionLevels> emotions =
             this.emotionLevelCollection1.GetEmotions;

            Double val = 0;
            Double valTheta = 0;
            Double valCompleteX = 0;
            Double valCompleteY = 0;
            foreach (EmotionLevels el in emotions)
            {
                if (!el.IsExcluded)
                {
                    val = el.PositiveEmotionValue;
                    valTheta = el.Angle;// *val / 250;
                    valCompleteX += val * Math.Sin(valTheta * Math.PI / 180 + Math.PI / 2);
                    valCompleteY += val * Math.Cos(valTheta * Math.PI / 180 + Math.PI / 2);
                }
            }


            if (val > 250)
                val = 250;

            if (Double.IsInfinity(valTheta))
            {
                val = 0;
                valTheta = 0;
            }

            pe.LocationMomentPtr = new System.Windows.Point(valCompleteX, valCompleteY);

        }

        private void Window_Closed(object sender, EventArgs e)
        {
            addEmotion.Close();
        }
    }
}
